"""
  Created by Amor on 2018-08-11
"""
import xadmin
from goods import models

__author__ = '骆杨'


class GoodsCategoryAdmin(object):
    list_display = ['name', 'category_type', 'parent_category', 'add_time']


class GoodsCategoryBrandAdmin(object):
    list_display = ['category', 'image', 'name', 'desc']

    def get_context(self):
        context = super().get_context()
        if 'form' in context:
            context['form'].fields['category'].queryset = models.GoodsCategory.objects.filter(category_type=1)
        return context


class GoodsAdmin(object):
    style_fields = {'goods_desc': 'ueditor'}


class GoodsImageAdmin(object):
    pass


class BannerAdmin(object):
    pass


class HotSearchAdmin(object):
    pass


class IndexAdAdmin(object):

    def get_context(self):
        context = super().get_context()
        if 'form' in context:
            context['form'].fields['category'].queryset = models.GoodsCategory.objects.filter(category_type=1)
        return context


xadmin.site.register(models.GoodsCategory, GoodsCategoryAdmin)
xadmin.site.register(models.GoodsCategoryBrand, GoodsCategoryBrandAdmin)
xadmin.site.register(models.Goods, GoodsAdmin)
xadmin.site.register(models.GoodsImage, GoodsImageAdmin)
xadmin.site.register(models.Banner, BannerAdmin)
xadmin.site.register(models.HotSearchWords, HotSearchAdmin)
xadmin.site.register(models.IndexAd, IndexAdAdmin)
